#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;
using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static constexpr int MAX =  5050;


int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    vector<pii> vp(n);
    for (int i = 0; i < n; i++) cin >> vp[i].first >> vp[i].second;
    sort(vp.begin(), vp.end());
    vector<int> vec(1, -1);
    int max_val = 0;
    for (int i = 0; i < n; i++)
    {
        if (vp[i].second > vec.back())
        {
            max_val++;
            vec.push_back(vp[i].second);
        }
        else *lower_bound(vec.begin(), vec.end(), vp[i].second) = vp[i].second;
    }
    cout << max_val;
    return 0;
}














